package pers.qianyu.month_202012.date_20201214;

/**
 * 343. 整数拆分
 * https://leetcode-cn.com/problems/integer-break/
 *
 * @author mizzle rain
 * @date 2020-12-13 21:06
 */
public class IntegerBreak {
    public int integerBreak(int n) {
        // dp[i] 表示数字 i 拆分之后的最大积
        int[] dp = new int[n + 1];
        for (int i = 2; i <= n; i++) {
            for (int j = 1; j < i; j++) {
                dp[i] = Math.max(dp[i],
                        Math.max(j * (i - j), j * dp[i - j]));
            }
        }
        return dp[n];
    }
}
